package org.example.springboot.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.example.springboot.DTO.RecommendationDTO;
import org.example.springboot.common.Result;
import org.example.springboot.service.RecommendationService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 图书推荐控制器
 */
@Tag(name="图书推荐接口")
@RestController
@RequestMapping("/recommendation")
public class RecommendationController {
    @Resource
    private RecommendationService recommendationService;
    
    @Operation(summary = "获取基于用户协同过滤的推荐")
    @GetMapping("/user-cf")
    public Result<?> getUserCFRecommendations(
            @RequestParam Long userId,
            @RequestParam(required = false, defaultValue = "10") Integer limit) {
        List<RecommendationDTO> recommendations = recommendationService.getUserCFRecommendations(userId, limit);
        return Result.success(recommendations);
    }
    
    @Operation(summary = "获取基于物品协同过滤的推荐")
    @GetMapping("/item-cf")
    public Result<?> getItemCFRecommendations(
            @RequestParam Long userId,
            @RequestParam(required = false, defaultValue = "10") Integer limit) {
        List<RecommendationDTO> recommendations = recommendationService.getItemCFRecommendations(userId, limit);
        return Result.success(recommendations);
    }
    
    @Operation(summary = "获取基于内容的推荐")
    @GetMapping("/content-based")
    public Result<?> getContentBasedRecommendations(
            @RequestParam Long userId,
            @RequestParam(required = false, defaultValue = "10") Integer limit) {
        List<RecommendationDTO> recommendations = recommendationService.getContentBasedRecommendations(userId, limit);
        return Result.success(recommendations);
    }
    
    @Operation(summary = "获取热门图书推荐")
    @GetMapping("/hot")
    public Result<?> getHotRecommendations(
            @RequestParam(required = false) Long userId,
            @RequestParam(required = false, defaultValue = "10") Integer limit) {
        List<RecommendationDTO> recommendations = recommendationService.getHotRecommendations(userId, limit);
        return Result.success(recommendations);
    }
    
    @Operation(summary = "获取新书推荐")
    @GetMapping("/new")
    public Result<?> getNewRecommendations(
            @RequestParam(required = false) Long userId,
            @RequestParam(required = false, defaultValue = "10") Integer limit) {
        List<RecommendationDTO> recommendations = recommendationService.getNewRecommendations(userId, limit);
        return Result.success(recommendations);
    }
    
    @Operation(summary = "获取混合推荐")
    @GetMapping("/hybrid")
    public Result<?> getHybridRecommendations(
            @RequestParam Long userId,
            @RequestParam(required = false, defaultValue = "12") Integer limit) {
        List<RecommendationDTO> recommendations = recommendationService.getHybridRecommendations(userId, limit);
        return Result.success(recommendations);
    }
    
    @Operation(summary = "获取相似图书推荐")
    @GetMapping("/similar")
    public Result<?> getSimilarBookRecommendations(
            @RequestParam Long bookId,
            @RequestParam(required = false) Long userId,
            @RequestParam(required = false, defaultValue = "6") Integer limit) {
        List<RecommendationDTO> recommendations = recommendationService.getSimilarBookRecommendations(bookId, userId, limit);
        return Result.success(recommendations);
    }
} 